import dom, { ajax } from "../init.js";
import { updateArticleList } from "../content/article/aritcle.js";
import { obj } from "../index.js";
import { articlelimit } from "../../util/interface.js";
import * as content from "../content/article/aritcle.js";
import { classche, initurl } from "../navigation/eventhandle.js";
import { HOST } from "../../config.js";
export default {
  async findtitle() {
    if (dom.index.index) classche(dom.index.index);
    obj.limit.x = 1;
    if ((dom.herder.findtitleipt as any).value === "") {
      content.getAllLimit();
      if (
        (dom.index.index as HTMLElement).classList.length >= 2 &&
        obj.url === "/article/getAllLimit"
      )
        return;
      obj.url = "/article/getAllLimit";
      content.initarticle();
    } else {
      if (obj._title === (dom.herder.findtitleipt as any).value) return;
      obj.url = "/article/findTitle";
      location.hash = "/find";
      content.initfindetitle();
    }
  },
  breaklogin() {
    console.log(Object.getOwnPropertyDescriptor(document, "cookie"));
    delCookie("feifan");
    location.href = HOST;
  },
};
function getCookie(name: string) {
  var arr,
    reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
  if ((arr = document.cookie.match(reg))) {
    return arr[2];
  } else {
    return null;
  }
}
//删除cookies
function delCookie(name: string) {
  var exp = new Date();
  exp.setTime(exp.getTime() - 1);
  //获取cookies
  var cval = getCookie(name);
  if (cval != null) {
    document.cookie =
      name + "=" + cval + ";expires=" + exp.toUTCString() + ";path=/";
  }
}
